/*    */ package com.qmsk.business.store.instockbill.service;
/*    */ 
/*    */ import com.qmsk.business.store.goodsStock.dao.GoodsStockDao;
/*    */ import com.qmsk.business.store.instockbill.dao.InStockBillDAO;
/*    */ import com.qmsk.business.store.instockdtl.dao.InStockDtlDAO;
/*    */ import com.utils.basic.ObjectComm;
/*    */ import com.utils.gson.in.GsonHeadManyRows;
/*    */ import com.utils.gson.in.GsonHeadOneRow;
/*    */ import java.sql.SQLException;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ 
/*    */ public class InStockBillService
/*    */ {
/*    */ 
/*    */   @Autowired
/*    */   private InStockBillDAO dao;
/*    */ 
/*    */   @Autowired
/*    */   private InStockDtlDAO dtlDao;
/*    */ 
/*    */   @Autowired
/*    */   private GoodsStockDao goodsStockDao;
/*    */ 
/*    */   public Integer insertOutBill(GsonHeadOneRow g, GsonHeadManyRows m)
/*    */     throws SQLException
/*    */   {
/* 28 */     Integer nResult = null;
/* 29 */     nResult = Integer.valueOf(this.dao.insertGsonHeadOneRow(g));
/* 30 */     if (nResult.intValue() > 0) {
/* 31 */       Long id = this.dao.getLastId();
/* 32 */       if (m.isExistsData()) {
/* 33 */         m.autoAddHeadData("id", id);
/* 34 */         m.setHeadValueOfObject("id", id);
/* 35 */         nResult = Integer.valueOf(this.dtlDao.insertGsonHeadManyRows(m));
/*    */       }
/*    */     }
/* 38 */     return nResult;
/*    */   }
/*    */ 
/*    */   public Integer check(Long id, HttpServletResponse response) throws SQLException
/*    */   {
/* 43 */     Integer nResult = null;
/* 44 */     nResult = this.dao.updateStatusOfId(id);
/*    */ 
/* 46 */     if (nResult.intValue() <= 0) {
/* 47 */       return nResult;
/*    */     }
/*    */ 
/* 50 */     GsonHeadManyRows g = this.dtlDao.getManyRowsOfId(id);
/* 51 */     if ((g != null) && (g.isExistsData())) {
/* 52 */       for (int k = 0; k < g.getData().length; ++k) {
/* 53 */         Long goodsId = ObjectComm.objectToLong(g.getValueOfName(
/* 54 */           "goodsId", k));
/* 55 */         Long houseId = ObjectComm.objectToLong(g.getValueOfName(
/* 56 */           "houseId", k));
/* 57 */         int count = this.goodsStockDao.getCountOfGoodsInStock(houseId, 
/* 58 */           goodsId).intValue();
/*    */ 
/* 59 */         Double sum = ObjectComm.objectToDouble(
/* 60 */           g.getValueOfName("nums", k), Integer.valueOf(0));
/*    */ 
/* 63 */         if (count == 0) {
/* 64 */           nResult = 
/* 65 */             Integer.valueOf(this.goodsStockDao
/* 65 */             .insertInStore(sum, goodsId, houseId));
/*    */         } else {
/* 67 */           Double num = this.goodsStockDao.getNumOfGoodsIdAndHouseId(
/* 68 */             houseId, goodsId);
/* 69 */           num = Double.valueOf(num.doubleValue() + sum.doubleValue());
/* 70 */           nResult = Integer.valueOf(this.goodsStockDao.updateCountOfGoodsIdAndHouseId(num, 
/* 71 */             houseId, goodsId));
/*    */         }
/*    */       }
/*    */     }
/* 75 */     return nResult;
/*    */   }
/*    */ 
/*    */   public String getInNo(Long shopId) throws SQLException {
/* 79 */     return this.dao.getMaxBillNo(shopId);
/*    */   }
/*    */ 
/*    */   public Long getLastId() throws SQLException {
/* 83 */     return this.dao.getLastId();
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.store.instockbill.service.InStockBillService
 * JD-Core Version:    0.5.3
 */